<?php
namespace Model\UserBundle\Service;

use Base\BaseService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Model\UserBundle\Model\UserLoginLogModel;

class UserService extends BaseService  implements AuthenticationSuccessHandlerInterface ,AuthenticationFailureHandlerInterface
{

    /*登录认证成功后处理必须有*/
    public function onAuthenticationSuccess(Request $request, TokenInterface $token){
        $userLoginLogModel = new UserLoginLogModel($this->getDoctrine());
        $loginInfo = $userLoginLogModel->createLoginLogInfo($request);
        $userLoginLogModel->addLoginLog($loginInfo);
        return $this->redirectToRoute("WebUserInfo");
    }
    /*登录认证失败后处理必须有*/
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception){
        $userLoginLogModel = new UserLoginLogModel($this->getDoctrine());
        $loginInfo = $userLoginLogModel->createLoginLogInfo($request);
        $userLoginLogModel->addLoginLog($loginInfo);
        return $this->redirectToRoute("WebUserLogin");
    }

}

